﻿
Imports System.Runtime.CompilerServices

Public Module _network
    <Extension()> Public Function parse_tcp_parameters(ByVal v As section,
                                                       Optional ByRef is_outgoing As String = Nothing,
                                                       Optional ByRef host As String = Nothing,
                                                       Optional ByRef port As String = Nothing,
                                                       Optional ByRef target As String = Nothing,
                                                       Optional ByRef token As String = Nothing,
                                                       Optional ByRef max_connecting As String = Nothing,
                                                       Optional ByRef max_connected As String = Nothing,
                                                       Optional ByRef no_delay As String = Nothing,
                                                       Optional ByRef connecting_timeout_ms As String = Nothing,
                                                       Optional ByRef response_timeout_ms As String = Nothing,
                                                       Optional ByRef send_rate_sec As String = Nothing,
                                                       Optional ByRef receive_rate_sec As String = Nothing,
                                                       Optional ByRef max_lifetime_ms As String = Nothing,
                                                       Optional ByRef ipv4 As String = Nothing,
                                                       Optional ByRef enable_keepalive As String = Nothing,
                                                       Optional ByRef first_keepalive_ms As String = Nothing,
                                                       Optional ByRef keepalive_interval_ms As String = Nothing,
                                                       Optional ByRef zipper As String = Nothing,
                                                       Optional ByRef encryptor As String = Nothing) _
                                                      As Boolean
        If v Is Nothing Then
            Return False
        Else
            is_outgoing = v("is-outgoing")
            host = v("host")
            port = v("port")
            target = v("target")
            token = v("token")
            max_connecting = v("max-connecting")
            max_connected = v("max-connected")
            no_delay = v("no-delay")
            connecting_timeout_ms = v("connecting-timeout-ms")
            response_timeout_ms = v("response-timeout-ms")
            send_rate_sec = v("send-rate-sec")
            receive_rate_sec = v("receive-rate-sec")
            max_lifetime_ms = v("max-lifetime-ms")
            ipv4 = v("ipv4")
            enable_keepalive = v("enable-keepalive")
            first_keepalive_ms = v("first-keepalive-ms")
            keepalive_interval_ms = v("keepalive-interval-ms")
            zipper = v("zipper")
            encryptor = v("encryptor")
            Return True
        End If
    End Function

    <Extension()> Public Function parse_http_parameters(
                                      ByVal v As section,
                                      Optional ByRef host As String = Nothing,
                                      Optional ByRef port As String = Nothing,
                                      Optional ByRef target As String = Nothing,
                                      Optional ByRef max_connection_count As String = Nothing,
                                      Optional ByRef connect_timeout_ms As String = Nothing,
                                      Optional ByRef response_timeout_ms As String = Nothing,
                                      Optional ByRef buff_size As String = Nothing,
                                      Optional ByRef single_copy_timeout_ms As String = Nothing,
                                      Optional ByRef copy_timeout_ms As String = Nothing,
                                      Optional ByRef max_content_length As String = Nothing) As Boolean
        If v Is Nothing Then
            Return False
        Else
            host = v("host")
            port = v("port")
            target = v("target")
            max_connection_count = v("max-connection-count")
            connect_timeout_ms = v("connect-timeout-ms")
            response_timeout_ms = v("response-timeout-ms")
            buff_size = v("buff-size")
            single_copy_timeout_ms = v("single-copy-timeout-ms")
            copy_timeout_ms = v("copy-timeout-ms")
            max_content_length = v("max-content-length")
            Return True
        End If
    End Function
End Module
